/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.eng.scc.core.details;

import com.eng.scc.core.data.Address;
import com.eng.scc.core.data.Company;
import com.eng.scc.core.data.Driver;
import com.eng.scc.core.data.People;
import com.eng.scc.core.db.manager.service.FuelControllerManagerService;
import com.eng.scc.core.util.HTMLFactory;
import com.eng.scc.core.view.ApplicationContext;

/**
 *
 * @author Rafael
 */
public class DriverDetails
{
    public static HTMLFactory.Body getDetails( Driver d )
    {
        HTMLFactory.Body body = new HTMLFactory.Body();
        
        try
        {
            People p = FuelControllerManagerService.getInstance().getPeople( d.getPeopleId() );
            
            HTMLFactory.Title title = new HTMLFactory.Title( "Motorista: " + p.getName() );
            
            body.addContent( title );
            
            HTMLFactory.TableDetails details = new HTMLFactory.TableDetails();
            
            Company company = FuelControllerManagerService.getInstance().getCompany( d.getCompanyId() );
            
            details.addItem( "Empresa", company.getFantasyName());
            details.addItem( "CPF", p.getCpf(), true);
            details.addItem( "RG", p.getRg(), true );
            
            Address address = FuelControllerManagerService.getInstance().getAddress( p.getAddressId() );
            
            if ( address != null )
            {
                details.addItem( "Estado", FuelControllerManagerService.getInstance().getHomeState( address.getHomeState() ).getName() );
                details.addItem( "Cidade", FuelControllerManagerService.getInstance().getCity( address.getCityId() ).getName() );
                details.addItem( "CEP", address.getCep() );
                details.addItem( "Endereço", address.getName() );
                details.addItem( "Nº", address.getNumber() );
            }
            
            details.addItem( "Email", p.getEmail() );
            details.addItem( "Gênero", p.getGender() == 1 ? "Feminino" : "Masculino" );
            details.addItem( "Telefone", p.getFixPhone(), true );
            details.addItem( "Telefone Celular", p.getMobilePhone(), true );
            details.addItem( "Comissão Padrão", d.getDefaultComission() );
            
            body.addContent( details );
            
            body.addContent( new HTMLFactory.Title( "Carteira de Motorista " ) );
            
            HTMLFactory.TableDetails cm = new HTMLFactory.TableDetails();
            cm.addItem( "Número", d.getCnh() );
            cm.addItem( "Categoria", d.getCnhCategory() );
            cm.addItem( "Data de Vencimento", d.getCnhDue() );
            body.addContent( cm );

        }
        catch ( Exception e )
        {
            ApplicationContext.getInstance().saveLog( e );
        }
        
        return body;
    }
}
